package TEST0813;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Number1 {
    public static void main(String[] args) throws IOException {
        BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine().trim());

        long[]digitCnt=new long[10]; //1-9
        long[]lenCnt=new long[12];
        int maxLen=1;

        //收集位数
        int got=0;
        while(got<n){
            StringTokenizer st=new StringTokenizer(br.readLine());
            while (st.hasMoreTokens()&&got<n){
                String s=st.nextToken();
                got++;
                int L=s.length();
                lenCnt[L]++;
                maxLen=Math.max(maxLen,L);
                for (int i=0;i<L;i++){
                    int d=s.charAt(i)-'0';
                    if(d!=0){
                        digitCnt[d]++;
                    }
                }
            }
        }

        long[]p10=new long[maxLen];
        p10[0]=1;
        for (int i=1;i<maxLen;i++){
            p10[i]=p10[i-1]*10L;
        }

        long[] suf=new long[maxLen+2];
        long acc=0;
        for(int L=maxLen;L>=1;L--){
            acc+=lenCnt[L];
            suf[L]=acc;
        }

        long ans=0;
        int d=9;
        for(int k=maxLen-1;k>=0;k--){
            long need =suf[k+1];
            while (need>0&&d>=1){
                while(d>=1&&digitCnt[d]==0){
                    d--;
                }
                if(d<1){
                    break;
                }
                long take=Math.min(need,digitCnt[d]);
                ans+=take*d*p10[k];
                need-=take;
                digitCnt[d]-=take;
            }
        }
        System.out.println(ans);


    }
}
